﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNet.Common;
using DotNet.Data.Factory;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace DotNet.Data
{
	public class Tab_AdminDal
	{
		IDBHelp db = DBHelp.Create();
		 Hashtable htSyn = Hashtable.Synchronized(new Hashtable());
		StringBuilder strSql = new StringBuilder();

		#region 是否存在该记录
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		/// <param name="adminID">标识列ID</param>
		public bool Exists(int adminID)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select count(1) from [Tab_Admin] where adminID=@adminid ");
			htSyn.Add("@adminid", adminID);
			return db.IsExists(strSql.ToString(), htSyn);
		}
		#endregion

		#region 得到该表数据列表
		/// <summary>
		/// 得到该表数据列表
		/// </summary>
		public IList<Tab_Admin> GetModel()
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("Select [adminID],[adminDate],[adminTel],[adminQQ],[adminEmail],[adminUserName],[adminPwd],[adminSex] FROM [Tab_Admin]");
			 return getTab_AdminBySql(strSql.ToString());
		}
		#endregion

		#region 根据标识列查询实体
		/// <summary>
		/// 根据标识列查询实体
		/// </summary>
		/// <param name="adminID">标识列ID</param>
		/// <returns></returns>
		public Tab_Admin GetModel(int adminid)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select [adminID],[adminDate],[adminTel],[adminQQ],[adminEmail],[adminUserName],[adminPwd],[adminSex] FROM [Tab_Admin]");
			strSql.Append(" where adminID=@adminid ");
			htSyn.Add("@adminid", adminid);
			DataTable dt = db.GetDataTable(strSql.ToString(), htSyn);
			Tab_Admin tab_adminModel = new Tab_Admin();
			if (dt.Rows.Count > 0)
			{
				tab_adminModel.adminDate=dt.Rows[0]["adminDate"].ToString();
				tab_adminModel.adminTel=dt.Rows[0]["adminTel"].ToString();
				tab_adminModel.adminQQ=dt.Rows[0]["adminQQ"].ToString();
				tab_adminModel.adminEmail=dt.Rows[0]["adminEmail"].ToString();
				tab_adminModel.adminUserName=dt.Rows[0]["adminUserName"].ToString();
				tab_adminModel.adminPwd=dt.Rows[0]["adminPwd"].ToString();
				tab_adminModel.adminSex=dt.Rows[0]["adminSex"].ToString();
			}
			return tab_adminModel;
		}
		#endregion

		#region 修改信息
		/// <summary>
		/// 修改信息
		/// </summary>
		/// <param name="Tab_Admin">实体</param>
		/// <returns></returns>
		public bool Update(Tab_Admin tab_adminModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("update [Tab_Admin] set ");
			strSql.Append("[adminDate]=@admindate,");
			strSql.Append("[adminTel]=@admintel,");
			strSql.Append("[adminQQ]=@adminqq,");
			strSql.Append("[adminEmail]=@adminemail,");
			strSql.Append("[adminUserName]=@adminusername,");
			strSql.Append("[adminPwd]=@adminpwd,");
			strSql.Append("[adminSex]=@adminsex");

			strSql.Append(" where adminID=@adminid ");
			htSyn.Add("@adminid", tab_adminModel.adminID);
			htSyn.Add("@admindate", tab_adminModel.adminDate);
			htSyn.Add("@admintel", tab_adminModel.adminTel);
			htSyn.Add("@adminqq", tab_adminModel.adminQQ);
			htSyn.Add("@adminemail", tab_adminModel.adminEmail);
			htSyn.Add("@adminusername", tab_adminModel.adminUserName);
			htSyn.Add("@adminpwd", tab_adminModel.adminPwd);
			htSyn.Add("@adminsex", tab_adminModel.adminSex);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 删除信息
		/// <summary>
		/// 删除信息
		/// </summary>
		/// <param name="adminID">标识列ID</param>
		/// <returns></returns>
		public bool Delete(int adminID)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("delete from [Tab_Admin] where adminID=@adminid");
			htSyn.Add("adminid", adminID);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 添加信息
		/// <summary>
		/// 添加信息
		/// </summary>
		/// <param name="Tab_Admin">实体</param>
		/// <returns></returns>
		public bool Insert(Tab_Admin tab_adminModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("insert into [Tab_Admin]([adminDate],[adminTel],[adminQQ],[adminEmail],[adminUserName],[adminPwd],[adminSex]) values (@admindate,@admintel,@adminqq,@adminemail,@adminusername,@adminpwd,@adminsex)");
			htSyn.Add("@admindate", tab_adminModel.adminDate);
			htSyn.Add("@admintel", tab_adminModel.adminTel);
			htSyn.Add("@adminqq", tab_adminModel.adminQQ);
			htSyn.Add("@adminemail", tab_adminModel.adminEmail);
			htSyn.Add("@adminusername", tab_adminModel.adminUserName);
			htSyn.Add("@adminpwd", tab_adminModel.adminPwd);
			htSyn.Add("@adminsex", tab_adminModel.adminSex);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 根据SQL语句获取集合
		/// <summary>
		///根据SQL语句获取集合
		/// </summary>
		/// <param name="strSql">sql语句</param>
		public IList<Tab_Admin> getTab_AdminBySql(string strSql)
		{
			IList<Tab_Admin> list = new List<Tab_Admin>();
			DataTable dt = db.GetDataTable(strSql);
			if (dt.Rows.Count > 0)
			{
				foreach (DataRow dr in dt.Rows)
				{
					Tab_Admin tab_adminModel = new Tab_Admin();
					tab_adminModel.adminID= Convert.ToInt32(dr["adminID"]);
					tab_adminModel.adminDate=dr["adminDate"].ToString();
					tab_adminModel.adminTel=dr["adminTel"].ToString();
					tab_adminModel.adminQQ=dr["adminQQ"].ToString();
					tab_adminModel.adminEmail=dr["adminEmail"].ToString();
					tab_adminModel.adminUserName=dr["adminUserName"].ToString();
					tab_adminModel.adminPwd=dr["adminPwd"].ToString();
					tab_adminModel.adminSex=dr["adminSex"].ToString();
					list.Add(tab_adminModel);
				}
			}
			return list;
		}
		#endregion
	}
}
